package com.blog.boot.service.system;

import com.blog.boot.api.entity.UserEntity;
import com.blog.boot.api.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

/**
 * @author : cailong
 * @since : Created in 上午 10:39 2018/12/19 0019
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public void reg(UserEntity userEntity){
        mongoTemplate.insert(userEntity);
    }
    public UserEntity findUserByUserName(String username){
        Query query = new Query(Criteria.where("username").is(username));
        return mongoTemplate.findOne(query, UserEntity.class);
    }

    @Override
    public UserEntity findUserByUserEmail(String email) {
        Query query = new Query(Criteria.where("email").is(email));
        return mongoTemplate.findOne(query, UserEntity.class);
    }

    @Override
    public UserEntity findUserByUserId(Long id) {
        Query query = new Query(Criteria.where("_id").is(id));
        return mongoTemplate.findOne(query, UserEntity.class);
    }
}
